﻿// ---------------------------------------------------------------------------------------------------
// <copyright file="CopperfieldConfiguration.cs" company="Elephant Insurance Services, LLC">
//     Copyright (c) 2012 All Right Reserved
// </copyright>
// <author>Chris Hines</author>
// <date>2012-11-08</date>
// <summary>
//     The CopperfieldConfiguration Class
// </summary>
// ---------------------------------------------------------------------------------------------------

namespace Copperfield
{
    using System;
    using System.Collections.Generic;

    /// <summary>
    /// Support class for framework configuration
    /// </summary>
    public static class CopperfieldConfiguration
    {
        /// <summary>
        /// Gets the configuration expression collection
        /// </summary>
        /// <value>
        /// The configuration expression collection
        /// </value>
        private static readonly List<IContextResolutionConfigurationExpression> configurationExpressions = new List<IContextResolutionConfigurationExpression>();

        /// <summary>
        /// Gets the resolution delegate
        /// </summary>
        /// <value>
        /// The resolution delegate
        /// </value>
        internal static Func<Type, object> ResolutionDelegate { get; private set; }

        /// <summary>
        /// Configures the instance resolution delegate
        /// </summary>
        /// <param name="resolutionDelegate">The instance resolution delegate</param>
        public static void InstancesAreResolvedBy(Func<Type, object> resolutionDelegate)
        {
            AssemblyScanner.ScanForPluggableTypes();

            ResolutionDelegate = resolutionDelegate;
        }

        /// <summary>
        /// Configures plugin instances
        /// </summary>
        /// <param name="pluginConfigurationDelegate">The plugin configuration delegate</param>
        public static void ConfigurePluginInstances(Action<Type, Type, Func<Type, Type, object>> pluginConfigurationDelegate)
        {
            if (pluginConfigurationDelegate == null)
            {
                throw new ArgumentNullException("pluginConfigurationDelegate", "The plugin configuration delegate can not be null.");
            }

            AssemblyScanner.ConfigurePluginTypes(pluginConfigurationDelegate);
        }

        /// <summary>
        /// Returns the collection of context resolution configuration expressions
        /// </summary>
        /// <returns>
        /// The collection of context resolution configuration expressions
        /// </returns>
        public static List<IContextResolutionConfigurationExpression> ContextResolutionConfigurationExpressions()
        {
            return configurationExpressions;
        }
    }
}
